package com.supervision.manage.service

import com.fly.base.threadpool.ExceptionNotify
import com.fly.base.util.DateFormatUtil
import com.fly.base.util.Util
import com.supervision.domain.enums.SystemLogEnum
import com.supervision.domain.model.SystemLog
import org.springframework.beans.factory.annotation.Value
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Service

/**
 *  Created by whis on 2019-07-05
 */
@Service
open class ExceptionNotifyService : ExceptionNotify {

    @Value("\${error.report:false}")
    private val errorReport: Boolean = false

    @Async("asyncExecutor")
    override fun sendErrorMessage(stackTrace: String, uri: String, parameterMap: MutableMap<String, Array<String>>, errorMsg: String) {
        val systemLog = SystemLog()
        systemLog.app = SystemLogEnum.APP_MANAGE.code
        systemLog.uri = uri
        systemLog.paramsMap = Util.jsonEncode(parameterMap)
        systemLog.errorMsg = errorMsg
        systemLog.staceTrace = stackTrace
        systemLog.reqTime = DateFormatUtil.timeFormat()
        systemLog.save()
    }
}